import os
import time
import multiprocessing

# 打印10个数字,每次间隔0.5秒
def func():
     for i in range(10):
          print(os.getpid(), i)
          time.sleep(3)

if __name__ == "__main__":
     # 指定进程池大小
     process_num = 5
     pool = multiprocessing.Pool(process_num)
     for p in range(process_num):
          # 阻塞式
          pool.apply(func)
          # 非阻塞式
          #   pool.apply_async(func)
     pool.close()
     pool.join()
     print("end")